package dabs.engine;


public class Condenser extends Converter implements AcceptsModifier{
	private int condensingSpeed;
	private boolean condensorFault;
	private int timeToFault;
	private int timeLeftFault;
	
	public Condenser(PowerPlant plant, String name, int conversionRate, int condensingSpeed) {
		super(plant, name, conversionRate);
		this.condensingSpeed = condensingSpeed;
	}

	public int getCondensingSpeed() { return condensingSpeed; }
	public void setCondensingSpeed(int condensingSpeed){ 
		if (condensorFault == false){ this.condensingSpeed = condensingSpeed; }
		else { 
			super.passMessage(new Notification(super.getName(), 
					"Condensor stalled for " + timeLeftFault + " seconds!"));
		}
	}
	
	public void handleModifier(Modifier modifier) {
		if (modifier instanceof TemporaryDisable){
			super.passMessage(new Notification(super.getName(), 
					"Condensor stalling in 30 seconds!"));
			timeToFault = 30;
			timeLeftFault = modifier.getDuration();
		}
	}
	
	public void tick(){
		if (timeToFault == 1){
			timeToFault--;
			condensorFault = true;
			condensingSpeed = 0;
			super.passMessage(new Notification(super.getName(),
					"Condensor is offline for " + timeLeftFault + " seconds!"));
		}
		else if (timeToFault > 1) { timeToFault--; }
		else if (condensorFault == false) { super.tick(); }
		else {
			if (timeLeftFault == 0){
				super.passMessage(new Notification(super.getName(), 
						"Condensor is back online!. Defaulting to 100% speed."));
				condensorFault = false; 
				condensingSpeed = 100;
				}
			else { timeLeftFault--; }
		}
	}
}
